<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取一个 OAuth 受保护的资源</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="oauth.enablesslchecks.html">OAuth::enableSSLChecks</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="oauth.generatesignature.html">OAuth::generateSignature</a></div>
 <div class="up"><a href="class.oauth.html">OAuth</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="oauth.fetch" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">OAuth::fetch</h1>
  <p class="verinfo">(PECL OAuth &gt;= 0.99.1)</p><p class="refpurpose"><span class="refname">OAuth::fetch</span> &mdash; <span class="dc-title">获取一个 OAuth 受保护的资源</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-oauth.fetch-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>OAuth::fetch</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$protected_resource_url</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$extra_parameters</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$http_method</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$http_headers</code></span>
  ]]] )</div>

  <p class="para rdfs-comment">
   获取一个资源。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-oauth.fetch-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">protected_resource_url</code></em></dt>

     <dd>

      <p class="para">
      OAuth 受保护资源的URL
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">extra_parameters</code></em></dt>

     <dd>

      <p class="para">
      和资源请求一起发送的额外参数。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">http_method</code></em></dt>

     <dd>

      <p class="para">
       <strong><code>OAUTH_HTTP_METHOD_*</code></strong> 系列 <a href="oauth.constants.html" class="link">OAUTH 常量</a>之一，GET、POST、PUT、HEAD 或 DELETE 其中的一个。
      </p>
      <p class="para">
       HEAD （<strong><code>OAUTH_HTTP_METHOD_HEAD</code></strong> ）可以用于先于请求发现信息（如果 OAuth 证书在 <em>Authorization</em> 头部）。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">http_headers</code></em></dt>

     <dd>

      <p class="para">
       HTTP 客户端头信息（像 User-Agent， Accept 等等这样的）。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-oauth.fetch-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-oauth.fetch-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>1.0.0</td>
       <td>
        以前失败时返回 <strong><code>NULL</code></strong>，而不是 <strong><code>FALSE</code></strong>。
       </td>
      </tr>

      <tr>
       <td>0.99.5</td>
       <td>
        新增 <em><code class="parameter">http_method</code></em> 参数
       </td>
      </tr>

      <tr>
       <td>0.99.8</td>
       <td>
        新增 <em><code class="parameter">http_headers</code></em> 参数
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-oauth.fetch-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5166">
    <p><strong>Example #1 <span class="function"><strong>OAuth::fetch()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$oauth&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">OAuth</span><span style="color: #007700">(</span><span style="color: #DD0000">"consumer_key"</span><span style="color: #007700">,</span><span style="color: #DD0000">"consumer_secret"</span><span style="color: #007700">,</span><span style="color: #0000BB">OAUTH_SIG_METHOD_HMACSHA1</span><span style="color: #007700">,</span><span style="color: #0000BB">OAUTH_AUTH_TYPE_AUTHORIZATION</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$oauth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setToken</span><span style="color: #007700">(</span><span style="color: #DD0000">"access_token"</span><span style="color: #007700">,</span><span style="color: #DD0000">"access_token_secret"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$oauth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://photos.example.net/photo?file=vacation.jpg"</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$response_info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$oauth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getLastResponseInfo</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Type:&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$response_info</span><span style="color: #007700">[</span><span style="color: #DD0000">"content_type"</span><span style="color: #007700">]}</span><span style="color: #DD0000">"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$oauth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getLastResponse</span><span style="color: #007700">();<br />}&nbsp;catch(</span><span style="color: #0000BB">OAuthException&nbsp;$E</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Exception&nbsp;caught!\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Response:&nbsp;"</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$E</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">lastResponse&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-oauth.fetch-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="oauth.getlastresponse.html" class="methodname" rel="rdfs-seeAlso">OAuth::getLastResponse()</a> - 获取最后一次的响应</span></li>
    <li class="member"><span class="methodname"><a href="oauth.getlastresponseinfo.html" class="methodname" rel="rdfs-seeAlso">OAuth::getLastResponseInfo()</a> - 获取关于最后一次响应的 HTTP 信息</span></li>
    <li class="member"><span class="methodname"><a href="oauth.settoken.html" class="methodname" rel="rdfs-seeAlso">OAuth::setToken()</a> - 设置令牌和 secret</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="oauth.enablesslchecks.html">OAuth::enableSSLChecks</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="oauth.generatesignature.html">OAuth::generateSignature</a></div>
 <div class="up"><a href="class.oauth.html">OAuth</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
